<!doctype html>
<html lang="zh-CN" data-theme="light">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <meta name="generator" content="VuePress 2.0.0-rc.0" />
    <meta name="theme" content="VuePress Theme Hope 2.0.0-rc.10" />
    <style>
      html {
        background: var(--bg-color, #fff);
      }

      html[data-theme="dark"] {
        background: var(--bg-color, #1d1e1f);
      }

      body {
        background: var(--bg-color);
      }
    </style>
    <script>
      const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
      const systemDarkMode =
        window.matchMedia &&
        window.matchMedia("(prefers-color-scheme: dark)").matches;

      if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
        document.documentElement.setAttribute("data-theme", "dark");
      }
    </script>
    <meta property="og:url" content="https://github.com/hylexus/jt-framework/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html"><meta property="og:site_name" content="jt-framework-808"><meta property="og:title" content="自定义注解(v2.1.1)"><meta property="og:description" content="请先读我 这里说的自定义注解是通过 v2.1.1 中引入的注解别名机制来扩展的自定义注解。 下面就以位置上报报文中的经纬度字段和时间字段为例，演示如何扩展自己的注解。 示例1(GeoPoint) 目的 这里的经纬度其实就是将 4 字节的 DWORD 转为数字(Long)，然后再除以 10^6^。 但是内置的转换器实际上不支持从 DWORD 到 Doub..."><meta property="og:type" content="article"><meta property="og:locale" content="zh-CN"><meta property="og:updated_time" content="2023-10-04T14:10:45.000Z"><meta property="article:author" content="hylexus"><meta property="article:modified_time" content="2023-10-04T14:10:45.000Z"><script type="application/ld+json">{"@context":"https://schema.org","@type":"Article","headline":"自定义注解(v2.1.1)","image":[""],"dateModified":"2023-10-04T14:10:45.000Z","author":[{"@type":"Person","name":"hylexus","url":"https://github.com/hylexus"}]}</script><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><meta name="application-name" content="jt808"><meta name="theme-color" content="#3eaf7c"><title>自定义注解(v2.1.1) | jt-framework-808</title><meta name="description" content="请先读我 这里说的自定义注解是通过 v2.1.1 中引入的注解别名机制来扩展的自定义注解。 下面就以位置上报报文中的经纬度字段和时间字段为例，演示如何扩展自己的注解。 示例1(GeoPoint) 目的 这里的经纬度其实就是将 4 字节的 DWORD 转为数字(Long)，然后再除以 10^6^。 但是内置的转换器实际上不支持从 DWORD 到 Doub...">
    <link rel="preload" href="/jt-framework-docs-808/assets/style-e6RyMkrY.css" as="style"><link rel="stylesheet" href="/jt-framework-docs-808/assets/style-e6RyMkrY.css">
    <link rel="modulepreload" href="/jt-framework-docs-808/assets/app-u6neHPvl.js"><link rel="modulepreload" href="/jt-framework-docs-808/assets/custom-annotation.html-2id8Krw3.js"><link rel="modulepreload" href="/jt-framework-docs-808/assets/plugin-vue_export-helper-x3n3nnut.js"><link rel="modulepreload" href="/jt-framework-docs-808/assets/custom-annotation.html-QkdSZPV8.js">
    <link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-7ppXEBZQ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/about.html-FnbfxxjQ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/thanks.html-0vuPemV_.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/debug.html-9YvFcuvp.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-xepKEacO.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/package-parsing.html-obFW5Ph3.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/what-is-the-difference-between-v1-and-v2.html-0_XRlslB.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Q8x7qKMX.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/1.x.html-eH3Tt9x8.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/2.0.x.html-KsDoiQ07.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/latest.html-rTPE6SdK.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-z4ai6-uc.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/type-mapping.html-pyYi8Tm7.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2011.html-98MqYKri.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2013.html-SoKAsP9J.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2019.html-Wf8IPhHL.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-lv7j9Luh.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-xsrcbSMf.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/features.html-ifgZNfaE.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/message-processor.html-xXSWNBdm.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/others.html-DkK2_Tbs.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/protocol.html-9KgVrAaZ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/server.html-y6DhzKiT.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/sub-package.html-2shJXfzg.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-jq0IBW1U.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-NgIA0YgS.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/exception-handler.html-G7r7SJse.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-X6Ib4FmF.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-msg-parse-demo.html-H44igjjF.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-handler-register.html-3MkaZMWs.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-push.html-Jl1q56yt.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/req-msg-mapping.html-MTHtsOOA.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/resp-msg-mapping.html-6DWrIyVW.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-9OhKqu0O.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/protocol-introduction.html-Z9X-F0Ow.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/quick-start.html-WP2UzM3U.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-7BokFGPw.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/aware-interface.html-00YDqo2E.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/component-order.html-DogUZfph.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/design-of-msg-processing.html-k2QZn8BT.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/auth-validator-config.html-TpUWdOlW.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/escape-config.html-hUVqc2Om.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-rom-D4pK.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-builder.html-ukTglW-g.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-converter-config.html-5ZS2Wmpk.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-handler-config.html-tHmZoGYg.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-type-config.html-OmO4cs_k.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/netty-config.html-ajHR7And.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/session-config.html-p16JJGxR.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/terminal-validator-config.html-9mgAnKKO.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/annotation-alias.html-CmT8JqNb.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/data-type-mapping-via-alias.html-cHkxlhJy.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/data-type-mapping.html-Lfy5_-pH.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/exception-handler.html-LyU9pE0I.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-kKzkpc6v.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-batch-upload-msg-parse-demo.html-gJf-Hgam.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-upload-msg-parse-demo.html-zxfNH40H.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/notices-for-builtin-msg.html-ZiRtmDLh.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/req-msg-mapping.html-Un57eg9r.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/resp-msg-mapping.html-Zf_cP9wD.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/command-sender.html-8Z5c8hQK.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/handler-interceptor.html--2IfRUKk.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-rcLlVUn4.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-msg-handler-argument-resolver.html-__tQRe_G.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-msg-handler.html-S8QDE9f9.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-processing-overview.html-v8looRCM.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-sub-package.html-9vZnqf7E.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/response-msg-handler.html-r0lMAv4r.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/response-sub-package.html-LrgmUzt5.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/summary.html-1zG99_MY.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/codec-config.html-JqLzJcnw.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-qsQN9vd7.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt-808-request-filter.html-ONMm7oOl.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/netty-config.html-kLr59yqh.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-lifecycle-listener.html-hNY-QRig.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/session-config.html-GBEJfJQ-.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/sub-package-config.html-UT5yKt2z.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/aware-interface.html-Q_TlqJ6H.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-QiyCB5uP.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-NjbGBbd1.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/migrating-from-2.0.x-to-2.1.x.html-czQm_uXf.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/building-from-source.html-MChwdFDk.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/compatibility.html-rG6UzAz1.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-vYhgbkKE.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt808-msg-type-parser.html-5UC1IaXg.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/maven-samples.html-KBqV2Ujm.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/quick-start.html-ftRpsGSm.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/terminology.html-ygzDBUEI.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/bit-operator.html-z-uoTlLC.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/byte-array-container.html-n8XzwGgu.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/byte-buf-container.html-CI3M4S9N.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-8J0_ID0a.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt808-data-type-ops.html-To91Ao68.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-builder.html-Dl6Scrw2.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/404.html-EBzvJi0F.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-VuFua8Zf.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-peV-YZk4.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html--2jndh5j.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-UVEAbiYr.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-KinuErC-.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-qn8dVnBP.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-ypbXvbHj.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/about.html-Qq8oXK2a.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/thanks.html-cPOoHpsU.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/debug.html-sIQhcCY5.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-xvMidjEq.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/package-parsing.html-NAus2Cyp.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/what-is-the-difference-between-v1-and-v2.html-MYOLF-q2.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-rwNoCRa3.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/1.x.html-NtFgYabb.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/2.0.x.html-94pyup2U.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/latest.html-95TwFyFC.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-peCdrq4G.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/type-mapping.html-HbwWVV7E.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2011.html-LebO8m7J.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2013.html-xAqs41mO.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/v2019.html-PMxXHygA.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-qTtlZ9GA.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Pg53zI-6.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/features.html-PQ3PnGz_.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/message-processor.html-_kT-IkbP.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/others.html-D3icrJWm.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/protocol.html-TO1Gdzff.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/server.html-Nr4kwyPq.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/sub-package.html-6a33tllz.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-AfmCAwBT.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-f9KbBOG2.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/exception-handler.html-ix0oEP_w.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Llac9aPX.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-msg-parse-demo.html-0-imBWNF.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-handler-register.html-t-i5NphV.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-push.html-bvb6Fsx3.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/req-msg-mapping.html-9ZE-zykg.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/resp-msg-mapping.html-qfxc5_Wz.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-1j1S3cWs.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/protocol-introduction.html-UpzWBt7J.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/quick-start.html-xshsu0Xl.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-EIlI72gr.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/aware-interface.html-Tjtug-MJ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/component-order.html-wd5HPCAY.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/design-of-msg-processing.html-wtb26jbC.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/auth-validator-config.html-x25LeAuG.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/escape-config.html-b8b2av3N.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-HbMQttwp.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-builder.html-ZKonCVrT.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-converter-config.html-APK2WpBD.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-handler-config.html-nhvWQPUJ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-type-config.html-MEp15By3.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/netty-config.html-CrAhEk4l.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/session-config.html-XDG7RoeV.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/terminal-validator-config.html-Re1UBuoY.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/annotation-alias.html-oaExbp5B.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/data-type-mapping-via-alias.html-r_Tiuyo2.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/data-type-mapping.html-nX1gXZZx.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/exception-handler.html-xeaqA5YR.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-5J8-71jl.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-batch-upload-msg-parse-demo.html-Sf5lbr6c.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/location-upload-msg-parse-demo.html-l8BflCrN.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/notices-for-builtin-msg.html-L3f9O4mH.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/req-msg-mapping.html-LHk9UfRR.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/resp-msg-mapping.html-iOPby8Ln.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/command-sender.html-_vYxsKId.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/handler-interceptor.html-fmZvkvwx.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-uNtViOEj.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-msg-handler-argument-resolver.html-X_4PRJ5-.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-msg-handler.html-5pvqXdRO.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-processing-overview.html-2tZXHf_s.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-sub-package.html-mWU0kdoe.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/response-msg-handler.html-D_gMEbL1.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/response-sub-package.html-jzBdkHi8.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/summary.html-v9zhHUXZ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/codec-config.html-RuAro468.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Uqwd8wJq.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt-808-request-filter.html-BtpRxnTl.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/netty-config.html-uqFY28M3.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/request-lifecycle-listener.html-AcEMkUhz.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/session-config.html-7TvYIeCt.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/sub-package-config.html-g_zdMy5N.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/aware-interface.html-CANWvOU1.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-JAiLftdt.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-wlL6UbZ6.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/migrating-from-2.0.x-to-2.1.x.html-B7xCiAw9.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/building-from-source.html-mqKJJjTY.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/compatibility.html-JmddpXlk.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Hyg8CwUJ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt808-msg-type-parser.html-hTwnfe6n.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/maven-samples.html-09ZNuUC5.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/quick-start.html-TjDWbUWb.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/terminology.html-otwlBWu9.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/bit-operator.html-DsDm7qlg.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/byte-array-container.html-Wb0JKHBu.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/byte-buf-container.html-iD_WIXkI.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-Ub_Zihof.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/jt808-data-type-ops.html-2MV3_sIR.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/msg-builder.html-o2I1W9Li.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/404.html-udNHsca_.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-KL-nokqz.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-KVLWq_Mh.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-to6YNo7Q.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-zVKmRmwk.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-TWWD7Dsp.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/index.html-D8eCMQ9s.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/photoswipe.esm-08_zHRDQ.js" as="script"><link rel="prefetch" href="/jt-framework-docs-808/assets/SearchResult-kQEDqvtS.js" as="script">
  </head>
  <body>
    <div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content" class="vp-skip-link sr-only">跳至主要內容</a><!--]--><!--[--><div class="theme-container has-toc"><!--[--><header id="navbar" class="vp-navbar"><div class="vp-navbar-start"><button type="button" class="vp-toggle-sidebar-button" title="Toggle Sidebar"><span class="icon"></span></button><!--[--><!----><!--]--><!--[--><a class="vp-link vp-brand vp-brand" href="/jt-framework-docs-808/"><img class="vp-nav-logo" src="/jt-framework-docs-808/logo.png" aria-hidden><!----><span class="vp-site-name hide-in-pad">jt-framework-808</span></a><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-center"><!--[--><!----><!--]--><!--[--><nav class="vp-nav-links"><div class="nav-item hide-in-mobile"><a aria-label="指南" class="vp-link nav-link active nav-link active" href="/jt-framework-docs-808/v2/jt-808/guide/"><span class="font-icon icon iconfont icon-creative" style=""></span>指南<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="配置" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/v2/jt-808/config/"><span class="font-icon icon iconfont icon-setting" style=""></span>配置<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="协议扫盲" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/protocol-introduction/"><span class="font-icon icon iconfont icon-info" style=""></span>协议扫盲<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="FAQ" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/frequently-asked-questions/"><span class="font-icon icon iconfont icon-question" style=""></span>FAQ<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="升级指南" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/v2/jt-808/guide/migration/migrating-from-2.0.x-to-2.1.x.html"><span class="font-icon icon iconfont icon-merge" style=""></span>升级指南<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="发版记录" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/v2/release-notes/latest.html"><span class="font-icon icon iconfont icon-branch" style=""></span>发版记录<!----></a></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button type="button" class="dropdown-title" aria-label="生态"><span class="title"><span class="font-icon icon iconfont icon-app" style=""></span>生态</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a href="https://hylexus.gitee.io/jt-framework-docs-808/" rel="noopener noreferrer" target="_blank" aria-label="jt-framework-JT/T 808" class="nav-link"><!---->jt-framework-JT/T 808<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://hylexus.gitee.io/jt-framework-docs-1078/" rel="noopener noreferrer" target="_blank" aria-label="jt-framework-JT/T 1078(Beta)" class="nav-link"><!---->jt-framework-JT/T 1078(Beta)<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://hylexus.gitee.io/jt-framework-docs-dashboard/" rel="noopener noreferrer" target="_blank" aria-label="jt-framework-dashboard(Beta)" class="nav-link"><!---->jt-framework-dashboard(Beta)<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><a aria-label="致谢" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/thanks.html"><span class="font-icon icon iconfont icon-info" style=""></span>致谢<!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="关于我们" class="vp-link nav-link nav-link" href="/jt-framework-docs-808/about.html"><span class="font-icon icon iconfont icon-home" style=""></span>关于我们<!----></a></div></nav><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-end"><!--[--><!----><!--]--><!--[--><!----><div class="nav-item vp-repo"><a class="vp-repo-link" href="https://github.com/hylexus/jt-framework" target="_blank" rel="noopener noreferrer" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="icon github-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="github icon" style="width:1.25rem;height:1.25rem;vertical-align:middle;"><path d="M511.957 21.333C241.024 21.333 21.333 240.981 21.333 512c0 216.832 140.544 400.725 335.574 465.664 24.49 4.395 32.256-10.07 32.256-23.083 0-11.69.256-44.245 0-85.205-136.448 29.61-164.736-64.64-164.736-64.64-22.315-56.704-54.4-71.765-54.4-71.765-44.587-30.464 3.285-29.824 3.285-29.824 49.195 3.413 75.179 50.517 75.179 50.517 43.776 75.008 114.816 53.333 142.762 40.79 4.523-31.66 17.152-53.377 31.19-65.537-108.971-12.458-223.488-54.485-223.488-242.602 0-53.547 19.114-97.323 50.517-131.67-5.035-12.33-21.93-62.293 4.779-129.834 0 0 41.258-13.184 134.912 50.346a469.803 469.803 0 0 1 122.88-16.554c41.642.213 83.626 5.632 122.88 16.554 93.653-63.488 134.784-50.346 134.784-50.346 26.752 67.541 9.898 117.504 4.864 129.834 31.402 34.347 50.474 78.123 50.474 131.67 0 188.586-114.73 230.016-224.042 242.09 17.578 15.232 33.578 44.672 33.578 90.454v135.85c0 13.142 7.936 27.606 32.854 22.87C862.25 912.597 1002.667 728.747 1002.667 512c0-271.019-219.648-490.667-490.71-490.667z"></path></svg></a></div><!----><div class="nav-item hide-in-mobile"><button type="button" class="outlook-button" tabindex="-1" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" class="icon outlook-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="outlook icon"><path d="M224 800c0 9.6 3.2 44.8 6.4 54.4 6.4 48-48 76.8-48 76.8s80 41.6 147.2 0 134.4-134.4 38.4-195.2c-22.4-12.8-41.6-19.2-57.6-19.2C259.2 716.8 227.2 761.6 224 800zM560 675.2l-32 51.2c-51.2 51.2-83.2 32-83.2 32 25.6 67.2 0 112-12.8 128 25.6 6.4 51.2 9.6 80 9.6 54.4 0 102.4-9.6 150.4-32l0 0c3.2 0 3.2-3.2 3.2-3.2 22.4-16 12.8-35.2 6.4-44.8-9.6-12.8-12.8-25.6-12.8-41.6 0-54.4 60.8-99.2 137.6-99.2 6.4 0 12.8 0 22.4 0 12.8 0 38.4 9.6 48-25.6 0-3.2 0-3.2 3.2-6.4 0-3.2 3.2-6.4 3.2-6.4 6.4-16 6.4-16 6.4-19.2 9.6-35.2 16-73.6 16-115.2 0-105.6-41.6-198.4-108.8-268.8C704 396.8 560 675.2 560 675.2zM224 419.2c0-28.8 22.4-51.2 51.2-51.2 28.8 0 51.2 22.4 51.2 51.2 0 28.8-22.4 51.2-51.2 51.2C246.4 470.4 224 448 224 419.2zM320 284.8c0-22.4 19.2-41.6 41.6-41.6 22.4 0 41.6 19.2 41.6 41.6 0 22.4-19.2 41.6-41.6 41.6C339.2 326.4 320 307.2 320 284.8zM457.6 208c0-12.8 12.8-25.6 25.6-25.6 12.8 0 25.6 12.8 25.6 25.6 0 12.8-12.8 25.6-25.6 25.6C470.4 233.6 457.6 220.8 457.6 208zM128 505.6C128 592 153.6 672 201.6 736c28.8-60.8 112-60.8 124.8-60.8-16-51.2 16-99.2 16-99.2l316.8-422.4c-48-19.2-99.2-32-150.4-32C297.6 118.4 128 291.2 128 505.6zM764.8 86.4c-22.4 19.2-390.4 518.4-390.4 518.4-22.4 28.8-12.8 76.8 22.4 99.2l9.6 6.4c35.2 22.4 80 12.8 99.2-25.6 0 0 6.4-12.8 9.6-19.2 54.4-105.6 275.2-524.8 288-553.6 6.4-19.2-3.2-32-19.2-32C777.6 76.8 771.2 80 764.8 86.4z"></path></svg><div class="outlook-dropdown"><!----></div></button></div><!--[--><button type="button" class="search-pro-button" aria-label="搜索"><svg xmlns="http://www.w3.org/2000/svg" class="icon search-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="search icon"><path d="M192 480a256 256 0 1 1 512 0 256 256 0 0 1-512 0m631.776 362.496-143.2-143.168A318.464 318.464 0 0 0 768 480c0-176.736-143.264-320-320-320S128 303.264 128 480s143.264 320 320 320a318.016 318.016 0 0 0 184.16-58.592l146.336 146.368c12.512 12.48 32.768 12.48 45.28 0 12.48-12.512 12.48-32.768 0-45.28"></path></svg><div class="search-pro-placeholder">搜索</div><div class="search-pro-key-hints"><kbd class="search-pro-key">Ctrl</kbd><kbd class="search-pro-key">K</kbd></div></button><!--]--><!--]--><!--[--><!----><!--]--><button type="button" class="vp-toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false" aria-controls="nav-screen"><span><span class="vp-top"></span><span class="vp-middle"></span><span class="vp-bottom"></span></span></button></div></header><!----><!--]--><!----><div class="toggle-sidebar-wrapper"><span class="arrow start"></span></div><aside id="sidebar" class="vp-sidebar"><!--[--><!----><!--]--><ul class="vp-sidebar-links"><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-launch" style=""></span><span class="vp-sidebar-title">入门</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-api" style=""></span><span class="vp-sidebar-title">基础</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-tool" style=""></span><span class="vp-sidebar-title">辅助工具</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable active" type="button"><span class="font-icon icon iconfont icon-semantic" style=""></span><span class="vp-sidebar-title">注解驱动开发</span><span class="vp-arrow down"></span></button><ul class="vp-sidebar-links"><li><!--[--><a aria-label="数据类型转换(传统方式)" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/data-type-mapping.html"><span class="font-icon icon iconfont icon-map" style=""></span>数据类型转换(传统方式)<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="数据类型转换(注解别名,v2.1.1)" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/data-type-mapping-via-alias.html"><span class="font-icon icon iconfont icon-map" style=""></span>数据类型转换(注解别名,v2.1.1)<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="请求消息映射" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/req-msg-mapping.html"><span class="font-icon icon iconfont icon-at" style=""></span>请求消息映射<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="响应消息映射" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/resp-msg-mapping.html"><span class="font-icon icon iconfont icon-at" style=""></span>响应消息映射<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="注解别名(v2.1.1)" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/annotation-alias.html"><span class="font-icon icon iconfont icon-at" style=""></span>注解别名(v2.1.1)<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="自定义注解(v2.1.1)" class="vp-link nav-link active vp-sidebar-link vp-sidebar-page active nav-link active vp-sidebar-link vp-sidebar-page active" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html"><span class="font-icon icon iconfont icon-customize" style=""></span>自定义注解(v2.1.1)<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="请先读我" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#请先读我"><!---->请先读我<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="示例1(GeoPoint)" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#示例1-geopoint"><!---->示例1(GeoPoint)<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="目的" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#目的"><!---->目的<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="定义自己的注解" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#定义自己的注解"><!---->定义自己的注解<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="提供一个转换器" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#提供一个转换器"><!---->提供一个转换器<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="使用自定义注解" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#使用自定义注解"><!---->使用自定义注解<!----></a><ul class="vp-sidebar-sub-headers"></ul></li></ul></li><li class="vp-sidebar-sub-header"><a aria-label="示例2(BcdDateTime)" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#示例2-bcddatetime"><!---->示例2(BcdDateTime)<!----></a><ul class="vp-sidebar-sub-headers"><li class="vp-sidebar-sub-header"><a aria-label="目的" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#目的-1"><!---->目的<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="定义自己的注解" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#定义自己的注解-1"><!---->定义自己的注解<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="提供一个转换器" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#提供一个转换器-1"><!---->提供一个转换器<!----></a><ul class="vp-sidebar-sub-headers"></ul></li><li class="vp-sidebar-sub-header"><a aria-label="使用自定义注解" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#使用自定义注解-1"><!---->使用自定义注解<!----></a><ul class="vp-sidebar-sub-headers"></ul></li></ul></li><li class="vp-sidebar-sub-header"><a aria-label="其他说明" class="vp-link nav-link vp-sidebar-link vp-heading nav-link vp-sidebar-link vp-heading" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/custom-annotation.html#其他说明"><!---->其他说明<!----></a><ul class="vp-sidebar-sub-headers"></ul></li></ul><!--]--></li><li><!--[--><a aria-label="异常处理" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/exception-handler.html"><span class="font-icon icon iconfont icon-restrict" style=""></span>异常处理<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="位置上传报文解析示例" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/location-upload-msg-parse-demo.html"><span class="font-icon icon iconfont icon-code" style=""></span>位置上传报文解析示例<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="批量位置上传报文解析示例" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/location-batch-upload-msg-parse-demo.html"><span class="font-icon icon iconfont icon-code" style=""></span>批量位置上传报文解析示例<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li><li><!--[--><a aria-label="内置消息说明" class="vp-link nav-link vp-sidebar-link vp-sidebar-page nav-link vp-sidebar-link vp-sidebar-page" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/notices-for-builtin-msg.html"><span class="font-icon icon iconfont icon-notice" style=""></span>内置消息说明<!----></a><ul class="vp-sidebar-sub-headers"></ul><!--]--></li></ul></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-customize" style=""></span><span class="vp-sidebar-title">定制</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-more" style=""></span><span class="vp-sidebar-title">深入</span><span class="vp-arrow end"></span></button><!----></section></li><li><section class="vp-sidebar-group"><button class="vp-sidebar-heading clickable" type="button"><span class="font-icon icon iconfont icon-merge" style=""></span><span class="vp-sidebar-title">升级指南</span><span class="vp-arrow end"></span></button><!----></section></li></ul><!--[--><!----><!--]--></aside><!--[--><main id="main-content" class="vp-page"><!--[--><!--[--><!----><!--]--><!----><nav class="vp-breadcrumb disable"></nav><div class="vp-page-title"><h1><span class="font-icon icon iconfont icon-customize" style=""></span>自定义注解(v2.1.1)</h1><div class="page-info"><span class="page-author-info" aria-label="作者🖊" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon author-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="author icon"><path d="M649.6 633.6c86.4-48 147.2-144 147.2-249.6 0-160-128-288-288-288s-288 128-288 288c0 108.8 57.6 201.6 147.2 249.6-121.6 48-214.4 153.6-240 288-3.2 9.6 0 19.2 6.4 25.6 3.2 9.6 12.8 12.8 22.4 12.8h704c9.6 0 19.2-3.2 25.6-12.8 6.4-6.4 9.6-16 6.4-25.6-25.6-134.4-121.6-240-243.2-288z"></path></svg><span><a class="page-author-item" href="https://github.com/hylexus" target="_blank" rel="noopener noreferrer">hylexus</a></span><span property="author" content="hylexus"></span></span><!----><span class="page-date-info" aria-label="写作日期📅" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon calendar-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="calendar icon"><path d="M716.4 110.137c0-18.753-14.72-33.473-33.472-33.473-18.753 0-33.473 14.72-33.473 33.473v33.473h66.993v-33.473zm-334.87 0c0-18.753-14.72-33.473-33.473-33.473s-33.52 14.72-33.52 33.473v33.473h66.993v-33.473zm468.81 33.52H716.4v100.465c0 18.753-14.72 33.473-33.472 33.473a33.145 33.145 0 01-33.473-33.473V143.657H381.53v100.465c0 18.753-14.72 33.473-33.473 33.473a33.145 33.145 0 01-33.473-33.473V143.657H180.6A134.314 134.314 0 0046.66 277.595v535.756A134.314 134.314 0 00180.6 947.289h669.74a134.36 134.36 0 00133.94-133.938V277.595a134.314 134.314 0 00-133.94-133.938zm33.473 267.877H147.126a33.145 33.145 0 01-33.473-33.473c0-18.752 14.72-33.473 33.473-33.473h736.687c18.752 0 33.472 14.72 33.472 33.473a33.145 33.145 0 01-33.472 33.473z"></path></svg><span><!----></span><meta property="datePublished" content="2023-10-04T14:10:45.000Z"></span><!----><!----><span class="page-word-info" aria-label="字数🔠" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon word-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="word icon"><path d="M518.217 432.64V73.143A73.143 73.143 0 01603.43 1.097a512 512 0 01419.474 419.474 73.143 73.143 0 01-72.046 85.212H591.36a73.143 73.143 0 01-73.143-73.143z"></path><path d="M493.714 566.857h340.297a73.143 73.143 0 0173.143 85.577A457.143 457.143 0 11371.566 117.76a73.143 73.143 0 0185.577 73.143v339.383a36.571 36.571 0 0036.571 36.571z"></path></svg><span>约 961 字</span><meta property="wordCount" content="961"></span><span class="page-reading-time-info" aria-label="阅读时间⌛" data-balloon-pos="down"><svg xmlns="http://www.w3.org/2000/svg" class="icon timer-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="timer icon"><path d="M799.387 122.15c4.402-2.978 7.38-7.897 7.38-13.463v-1.165c0-8.933-7.38-16.312-16.312-16.312H256.33c-8.933 0-16.311 7.38-16.311 16.312v1.165c0 5.825 2.977 10.874 7.637 13.592 4.143 194.44 97.22 354.963 220.201 392.763-122.204 37.542-214.893 196.511-220.2 389.397-4.661 5.049-7.638 11.651-7.638 19.03v5.825h566.49v-5.825c0-7.379-2.849-13.981-7.509-18.9-5.049-193.016-97.867-351.985-220.2-389.527 123.24-37.67 216.446-198.453 220.588-392.892zM531.16 450.445v352.632c117.674 1.553 211.787 40.778 211.787 88.676H304.097c0-48.286 95.149-87.382 213.728-88.676V450.445c-93.077-3.107-167.901-81.297-167.901-177.093 0-8.803 6.99-15.793 15.793-15.793 8.803 0 15.794 6.99 15.794 15.793 0 80.261 63.69 145.635 142.01 145.635s142.011-65.374 142.011-145.635c0-8.803 6.99-15.793 15.794-15.793s15.793 6.99 15.793 15.793c0 95.019-73.789 172.82-165.96 177.093z"></path></svg><span>大约 3 分钟</span><meta property="timeRequired" content="PT3M"></span></div><hr></div><div class="toc-place-holder"><aside id="toc"><!--[--><!----><!--]--><div class="toc-header">此页内容<button type="button" class="print-button" title="打印"><svg xmlns="http://www.w3.org/2000/svg" class="icon print-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="print icon"><path d="M819.2 364.8h-44.8V128c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v236.8h-44.8C145.067 364.8 96 413.867 96 473.6v192c0 59.733 49.067 108.8 108.8 108.8h44.8V896c0 17.067 14.933 32 32 32h460.8c17.067 0 32-14.933 32-32V774.4h44.8c59.733 0 108.8-49.067 108.8-108.8v-192c0-59.733-49.067-108.8-108.8-108.8zM313.6 160h396.8v204.8H313.6V160zm396.8 704H313.6V620.8h396.8V864zM864 665.6c0 25.6-19.2 44.8-44.8 44.8h-44.8V588.8c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v121.6h-44.8c-25.6 0-44.8-19.2-44.8-44.8v-192c0-25.6 19.2-44.8 44.8-44.8h614.4c25.6 0 44.8 19.2 44.8 44.8v192z"></path></svg></button></div><div class="toc-wrapper"><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#请先读我">请先读我</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#示例1-geopoint">示例1(GeoPoint)</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#目的">目的</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#定义自己的注解">定义自己的注解</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#提供一个转换器">提供一个转换器</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#使用自定义注解">使用自定义注解</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#示例2-bcddatetime">示例2(BcdDateTime)</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#目的-1">目的</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#定义自己的注解-1">定义自己的注解</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#提供一个转换器-1">提供一个转换器</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#使用自定义注解-1">使用自定义注解</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#其他说明">其他说明</a></li><!----><!--]--></ul><div class="toc-marker" style="top:-1.7rem;"></div></div><!--[--><!----><!--]--></aside></div><!--[--><!----><!--]--><div class="theme-hope-content"><h1 id="自定义注解-v2-1-1" tabindex="-1"><a class="header-anchor" href="#自定义注解-v2-1-1" aria-hidden="true">#</a> 自定义注解(v2.1.1)</h1><h2 id="请先读我" tabindex="-1"><a class="header-anchor" href="#请先读我" aria-hidden="true">#</a> 请先读我</h2><p>这里说的自定义注解是通过 <strong>v2.1.1</strong> 中引入的注解别名机制来扩展的自定义注解。</p><p>下面就以位置上报报文中的经纬度字段和时间字段为例，演示如何扩展自己的注解。</p><p class=""><img src="/jt-framework-docs-808/img/v2/annotation-driven-dev/custom-annotation.png"></p><h2 id="示例1-geopoint" tabindex="-1"><a class="header-anchor" href="#示例1-geopoint" aria-hidden="true">#</a> 示例1(GeoPoint)</h2><h3 id="目的" tabindex="-1"><a class="header-anchor" href="#目的" aria-hidden="true">#</a> 目的</h3><p>这里的经纬度其实就是将 <strong>4</strong> 字节的 <code>DWORD</code> 转为数字(<code>Long</code>)，然后再除以 10<sup>6</sup>。</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@Jt808RequestBody</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BuiltinMsg0200V2013Alias</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>

    <span class="token comment">// (3). byte[8,12) DWORD 纬度</span>
    <span class="token annotation punctuation">@RequestFieldAlias.Dword</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">long</span> lat<span class="token punctuation">;</span>

    <span class="token comment">// (4). byte[12,16) DWORD 经度</span>
    <span class="token annotation punctuation">@RequestFieldAlias.Dword</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">long</span> lng<span class="token punctuation">;</span>

    <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是内置的转换器实际上不支持从 <code>DWORD</code> 到 <code>Double</code> 的转换，只能写成 <code>Long</code> 然后再手动除以 10<sup>6</sup> 转为浮点数。</p><p>不过你可以扩展自定义注解实现这个转换。</p><h3 id="定义自己的注解" tabindex="-1"><a class="header-anchor" href="#定义自己的注解" aria-hidden="true">#</a> 定义自己的注解</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Target</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token class-name">ElementType</span><span class="token punctuation">.</span><span class="token constant">FIELD</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Retention</span><span class="token punctuation">(</span><span class="token class-name">RetentionPolicy</span><span class="token punctuation">.</span><span class="token constant">RUNTIME</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Documented</span>
<span class="token annotation punctuation">@RequestField</span><span class="token punctuation">(</span>dataType <span class="token operator">=</span> <span class="token class-name">MsgDataType</span><span class="token punctuation">.</span><span class="token constant">DWORD</span><span class="token punctuation">,</span> order <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> customerFieldDeserializerClass <span class="token operator">=</span> <span class="token class-name">ExtendedJt808FieldDeserializerGeoPoint</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token annotation punctuation">@interface</span> <span class="token class-name">GeoPoint</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@AliasFor</span><span class="token punctuation">(</span>annotation <span class="token operator">=</span> <span class="token class-name">RequestField</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> attribute <span class="token operator">=</span> <span class="token string">&quot;order&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">int</span> <span class="token function">order</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@AliasFor</span><span class="token punctuation">(</span>annotation <span class="token operator">=</span> <span class="token class-name">RequestField</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> attribute <span class="token operator">=</span> <span class="token string">&quot;desc&quot;</span><span class="token punctuation">)</span>
    <span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span></span>String</span> <span class="token function">desc</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="提供一个转换器" tabindex="-1"><a class="header-anchor" href="#提供一个转换器" aria-hidden="true">#</a> 提供一个转换器</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 自定义的转换器 [不需要] 手动实例化, [也不需要] 注册到 `Jt808FieldDeserializerRegistry` 中</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExtendedJt808FieldDeserializerGeoPoint</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractExtendedJt808FieldDeserializer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">LongFieldDeserializer</span> delegate <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LongFieldDeserializer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Object</span> <span class="token function">deserialize</span><span class="token punctuation">(</span><span class="token class-name">ByteBuf</span> byteBuf<span class="token punctuation">,</span> <span class="token class-name">MsgDataType</span> msgDataType<span class="token punctuation">,</span> <span class="token keyword">int</span> start<span class="token punctuation">,</span> <span class="token keyword">int</span> length<span class="token punctuation">,</span> <span class="token class-name">Context</span> context<span class="token punctuation">)</span> <span class="token punctuation">{</span>

        <span class="token comment">// 1. 先委托内置的 LongFieldDeserializer 解析为 LONG</span>
        <span class="token keyword">final</span> <span class="token class-name">Long</span> dword <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>delegate<span class="token punctuation">.</span><span class="token function">deserialize</span><span class="token punctuation">(</span>byteBuf<span class="token punctuation">,</span> msgDataType<span class="token punctuation">,</span> start<span class="token punctuation">,</span> length<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> targetClass <span class="token operator">=</span> context<span class="token punctuation">.</span><span class="token function">fieldMetadata</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getFieldType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 2. 然后再根据自己的要求进一步转换</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Long</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token keyword">long</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> dword<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Double</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token keyword">double</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> dword <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> <span class="token number">1_000_000</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">BigDecimal</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">BigDecimal</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>dword<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">setScale</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">,</span> <span class="token class-name">RoundingMode</span><span class="token punctuation">.</span><span class="token constant">UP</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">divide</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">BigDecimal</span><span class="token punctuation">(</span><span class="token string">&quot;1000000&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">RoundingMode</span><span class="token punctuation">.</span><span class="token constant">UP</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Jt808AnnotationArgumentResolveException</span><span class="token punctuation">(</span><span class="token string">&quot;Cannot convert DataType from &quot;</span> <span class="token operator">+</span> msgDataType <span class="token operator">+</span> <span class="token string">&quot; to &quot;</span> <span class="token operator">+</span> targetClass<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="使用自定义注解" tabindex="-1"><a class="header-anchor" href="#使用自定义注解" aria-hidden="true">#</a> 使用自定义注解</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@Jt808RequestBody</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BuiltinMsg0200V2013Alias</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>

    <span class="token comment">// (3). byte[8,12) DWORD 纬度</span>
    <span class="token annotation punctuation">@GeoPoint</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">)</span>
    <span class="token comment">// 支持 long, double, BigDecimal</span>
    <span class="token keyword">private</span> <span class="token keyword">double</span> lat<span class="token punctuation">;</span>

    <span class="token comment">// (4). byte[12,16) DWORD 经度</span>
    <span class="token annotation punctuation">@GeoPoint</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">)</span>
    <span class="token comment">// 支持 long, double, BigDecimal</span>
    <span class="token keyword">private</span> <span class="token class-name">BigDecimal</span> lng<span class="token punctuation">;</span>

    <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="hint-container tip"><p class="hint-container-title">提示</p><p>实际上这里演示的这个注解已经在 <strong>2.1.1</strong> 中内置了, 全类名是 <code>@io.github.hylexus.jt.jt808.support.annotation.msg.req.RequestFieldAlias.GeoPoint</code>。</p></div><h2 id="示例2-bcddatetime" tabindex="-1"><a class="header-anchor" href="#示例2-bcddatetime" aria-hidden="true">#</a> 示例2(BcdDateTime)</h2><h3 id="目的-1" tabindex="-1"><a class="header-anchor" href="#目的-1" aria-hidden="true">#</a> 目的</h3><p>位置上报报文中的时间字段是以 <code>BCD</code> 格式编码的字符串，格式为 <code>yyMMddHHmmss</code>。</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@Accessors</span><span class="token punctuation">(</span>chain <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Jt808RequestBody</span>
<span class="token annotation punctuation">@BuiltinComponent</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BuiltinMsg0200V2013Alias</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>

    <span class="token comment">// (8). byte[22,28) BCD[6] 时间</span>
    <span class="token annotation punctuation">@RequestFieldAlias.Bcd</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">8</span><span class="token punctuation">,</span> length <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> time<span class="token punctuation">;</span>

    <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是内置的反序列化器并不支持直接从 <code>BCD</code> 转为 <code>Date</code> 或 <code>LocalDateTime</code>，只能转为 <code>String</code> 或其他类型。</p><p>从 <strong>2.1.1</strong> 开始，你可以定义自己的注解来完成这种特殊需求。</p><h3 id="定义自己的注解-1" tabindex="-1"><a class="header-anchor" href="#定义自己的注解-1" aria-hidden="true">#</a> 定义自己的注解</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Target</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token class-name">ElementType</span><span class="token punctuation">.</span><span class="token constant">FIELD</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Retention</span><span class="token punctuation">(</span><span class="token class-name">RetentionPolicy</span><span class="token punctuation">.</span><span class="token constant">RUNTIME</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Documented</span>
<span class="token annotation punctuation">@RequestField</span><span class="token punctuation">(</span>dataType <span class="token operator">=</span> <span class="token class-name">MsgDataType</span><span class="token punctuation">.</span><span class="token constant">BCD</span><span class="token punctuation">,</span> length <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">,</span> customerFieldDeserializerClass <span class="token operator">=</span> <span class="token class-name">MyExtendedJt808FieldDeserializerBcdTime</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> order <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token annotation punctuation">@interface</span> <span class="token class-name">BcdDateTime</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@AliasFor</span><span class="token punctuation">(</span>annotation <span class="token operator">=</span> <span class="token class-name">RequestField</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> attribute <span class="token operator">=</span> <span class="token string">&quot;order&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">int</span> <span class="token function">order</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@AliasFor</span><span class="token punctuation">(</span>annotation <span class="token operator">=</span> <span class="token class-name">RequestField</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> attribute <span class="token operator">=</span> <span class="token string">&quot;desc&quot;</span><span class="token punctuation">)</span>
    <span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span></span>String</span> <span class="token function">desc</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>

    <span class="token comment">// 也可以自己扩展注解的属性</span>
    <span class="token class-name">String</span> <span class="token function">pattern</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;yyMMddHHmmss&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="提供一个转换器-1" tabindex="-1"><a class="header-anchor" href="#提供一个转换器-1" aria-hidden="true">#</a> 提供一个转换器</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 自定义的转换器 [不需要] 手动实例化, [也不需要] 注册到 `Jt808FieldDeserializerRegistry` 中</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyExtendedJt808FieldDeserializerBcdTime</span> <span class="token keyword">extends</span> <span class="token class-name">AbstractExtendedJt808FieldDeserializer</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">final</span> <span class="token class-name">BcdFieldDeserializer</span> delegate <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BcdFieldDeserializer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Object</span> <span class="token function">deserialize</span><span class="token punctuation">(</span><span class="token class-name">ByteBuf</span> byteBuf<span class="token punctuation">,</span> <span class="token class-name">MsgDataType</span> msgDataType<span class="token punctuation">,</span> <span class="token keyword">int</span> start<span class="token punctuation">,</span> <span class="token keyword">int</span> length<span class="token punctuation">,</span> <span class="token class-name">Context</span> context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">final</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> targetClass <span class="token operator">=</span> context<span class="token punctuation">.</span><span class="token function">fieldMetadata</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getFieldType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">String</span> bcd <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>delegate<span class="token punctuation">.</span><span class="token function">deserialize</span><span class="token punctuation">(</span>byteBuf<span class="token punctuation">,</span> msgDataType<span class="token punctuation">,</span> start<span class="token punctuation">,</span> length<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">BcdDateTime</span> annotation <span class="token operator">=</span> context<span class="token punctuation">.</span><span class="token function">fieldMetadata</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getAnnotation</span><span class="token punctuation">(</span><span class="token class-name">BcdDateTime</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">final</span> <span class="token class-name">String</span> pattern <span class="token operator">=</span> annotation<span class="token punctuation">.</span><span class="token function">pattern</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>bcd<span class="token punctuation">,</span> <span class="token class-name">DateTimeFormatter</span><span class="token punctuation">.</span><span class="token function">ofPattern</span><span class="token punctuation">(</span>pattern<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">Date</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">try</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span>pattern<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>bcd<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">ParseException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Jt808FieldSerializerException</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">.</span><span class="token function">isAssignableFrom</span><span class="token punctuation">(</span>targetClass<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> bcd<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Jt808AnnotationArgumentResolveException</span><span class="token punctuation">(</span><span class="token string">&quot;Cannot convert DataType from &quot;</span> <span class="token operator">+</span> msgDataType <span class="token operator">+</span> <span class="token string">&quot; to &quot;</span> <span class="token operator">+</span> targetClass<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="使用自定义注解-1" tabindex="-1"><a class="header-anchor" href="#使用自定义注解-1" aria-hidden="true">#</a> 使用自定义注解</h3><p>现在可以通过自定义注解将 <code>BCD</code> 转换为 <code>LocalDateTime</code>、 <code>Date</code> 或 <code>String</code> 了：</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>
<span class="token annotation punctuation">@Data</span>
<span class="token annotation punctuation">@Accessors</span><span class="token punctuation">(</span>chain <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Jt808RequestBody</span>
<span class="token annotation punctuation">@BuiltinComponent</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BuiltinMsg0200V2013Alias</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>

    <span class="token comment">// (8). byte[22,28) BCD[6] 时间</span>
    <span class="token annotation punctuation">@BcdDateTime</span><span class="token punctuation">(</span>order <span class="token operator">=</span> <span class="token number">7</span><span class="token punctuation">,</span> pattern <span class="token operator">=</span> <span class="token string">&quot;yyMMddHHmmss&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">LocalDateTime</span> time<span class="token punctuation">;</span>
    <span class="token comment">// private Date time;</span>
    <span class="token comment">// private String time;</span>

    <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="hint-container tip"><p class="hint-container-title">提示</p><p>实际上这里演示的这个注解已经在 <strong>2.1.1</strong> 中内置了, 全类名是 <code>@io.github.hylexus.jt.jt808.support.annotation.msg.req.RequestFieldAlias.BcdDateTime</code>。</p></div><h2 id="其他说明" tabindex="-1"><a class="header-anchor" href="#其他说明" aria-hidden="true">#</a> 其他说明</h2><ul><li>内置的给 <code>@RequestField</code> 提供的别名都在 <code>@RequestFieldAlias</code> 中</li><li>要扩展 <code>@ResponseField</code> 也是同样的道理，可以参考 <code>@ResponseFieldAlias</code> 中内置的一堆别名</li><li>要扩展一种不支持的数据类型, 比如 <code>LWORD</code>(<code>Long Word</code>, <code>unsigned 64 bit</code>), 也可以通过注解别名实现</li></ul></div><!--[--><!----><!--]--><footer class="page-meta"><div class="meta-item edit-link"><a href="https://github.com/hylexus/jt-framework/edit/main/docs/v2/jt-808/guide/annotation-based-dev/custom-annotation.md" rel="noopener noreferrer" target="_blank" aria-label="在 GitHub 上编辑此页" class="nav-link label"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon edit-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="edit icon"><path d="M430.818 653.65a60.46 60.46 0 0 1-50.96-93.281l71.69-114.012 7.773-10.365L816.038 80.138A60.46 60.46 0 0 1 859.225 62a60.46 60.46 0 0 1 43.186 18.138l43.186 43.186a60.46 60.46 0 0 1 0 86.373L588.879 565.55l-8.637 8.637-117.466 68.234a60.46 60.46 0 0 1-31.958 11.229z"></path><path d="M728.802 962H252.891A190.883 190.883 0 0 1 62.008 771.98V296.934a190.883 190.883 0 0 1 190.883-192.61h267.754a60.46 60.46 0 0 1 0 120.92H252.891a69.962 69.962 0 0 0-69.098 69.099V771.98a69.962 69.962 0 0 0 69.098 69.098h475.911A69.962 69.962 0 0 0 797.9 771.98V503.363a60.46 60.46 0 1 1 120.922 0V771.98A190.883 190.883 0 0 1 728.802 962z"></path></svg><!--]-->在 GitHub 上编辑此页<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></div><div class="meta-item git-info"><div class="update-time"><span class="label">上次编辑于: </span><!----></div><div class="contributors"><span class="label">贡献者: </span><!--[--><!--[--><span class="contributor" title="email: hylexus@163.com">hylexus</span><!--]--><!--]--></div></div></footer><nav class="vp-page-nav"><a aria-label="注解别名(v2.1.1)" class="vp-link nav-link prev nav-link prev" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/annotation-alias.html"><div class="hint"><span class="arrow start"></span>上一页</div><div class="link"><span class="font-icon icon iconfont icon-at" style=""></span>注解别名(v2.1.1)</div></a><a aria-label="异常处理" class="vp-link nav-link next nav-link next" href="/jt-framework-docs-808/v2/jt-808/guide/annotation-based-dev/exception-handler.html"><div class="hint">下一页<span class="arrow end"></span></div><div class="link">异常处理<span class="font-icon icon iconfont icon-restrict" style=""></span></div></a></nav><!----><!--[--><!----><!--]--><!--]--></main><!--]--><footer class="vp-footer-wrapper"><div class="vp-footer"><a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">备案号: 沪ICP备2022029946号-2</a ></div><!----></footer></div><!--]--><!--]--><!----><!----><!--]--></div>
    <script type="module" src="/jt-framework-docs-808/assets/app-u6neHPvl.js" defer></script>
  </body>
</html>
